package com.zzl.web;

import com.alibaba.fastjson.JSONObject;
import com.zzl.services.GradeServices;
import com.zzl.services.StudentServices;
import com.zzl.services.impl.GradeServicesImpl;
import com.zzl.services.impl.StudentServicrImpl;
import com.zzl.util.DbUtil;
import com.zzl.util.ResponseTypeUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;

public class StudentDeleteServlet extends HttpServlet {
    DbUtil dbUtil=new DbUtil();
    StudentServices studentServices=new StudentServicrImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String delIds=req.getParameter("delIds");
        System.out.println(delIds);
        Connection con=null;
        try {
            con=dbUtil.getCon();
            JSONObject result=new JSONObject();
            int delNums= studentServices.studentDelete(con,delIds);
            if(delNums>0){
                result.put("success","true");
                result.put("delNums",delNums);
            }else {
                result.put("errorMsg","删除失败");
            }
            ResponseTypeUtil.write(resp,result);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                dbUtil.closeCon(con);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }

}
